<!--企业编辑-->
<template>
	<div class="detail-container">
		<el-link icon="el-icon-arrow-left" :underline="false" @click="goBack">返回</el-link>
		<div class="name">编辑企业</div>
		<el-form ref="baseForm" :model="baseForm" :rules="baseRules" class="base-form" label-position="left"
			label-width="160px">
			<div class="form-part">
				<div class="title">
					<span class="mr">企业基本信息</span>
					<el-button v-if="!!unitOrgCode" @click="showDialog('orderFormDialogVisible')">成单记录新增</el-button>
				</div>
				<div class="row-item">
					<div class="col-item">
						<el-form-item label="单位名称" prop="unitName">
							<el-input placeholder="请输入单位名称" v-model="baseForm.unitName"
								:disabled="roles[0].authority === 'ROLE_SUPPORT'"></el-input>
						</el-form-item>
					</div>
					<div class="col-item">
						<el-form-item label="统一信用代码" prop="unitOrgCode">
							<el-input placeholder="请输入统一信用代码" v-model="baseForm.unitOrgCode"
								:disabled="roles[0].authority === 'ROLE_SUPPORT'"></el-input>
						</el-form-item>
					</div>
				</div>
				<div class="row-item">
					<div class="col-item">
						<el-form-item label="销售员" prop="supportUnitCode">
							<el-select v-model="baseForm.supportUnitCode" placeholder="请选择" style="width: 100%"
								:disabled="roles[0].authority === 'ROLE_SUPPORT'">
								<el-option v-for="(it, ind) in supportUnitDict" :key="ind" :label="it.label"
									:value="it.value"></el-option>
							</el-select>
						</el-form-item>
					</div>
					<div class="col-item">
						<el-form-item label="行业" prop="industryLabelCode">
							<el-select v-model="baseForm.industryLabelCode" placeholder="请选择" style="width: 100%">
								<el-option v-for="(it, ind) in labelHybqDict" :key="ind" :label="it.label"
									:value="it.value"></el-option>
							</el-select>
						</el-form-item>
					</div>
				</div>
				<div class="row-item">
					<div class="col-item">
						<el-form-item label="实际办公地址" prop="unitStreet">
							<div style="display: flex">
								<el-select placeholder="请选择所在街道" v-model="baseForm.unitStreet"
									style="margin-right: .13rem">
									<el-option v-for="(it, ind) in unitStreetDict" :key="ind" :label="it.label"
										:value="it.value"></el-option>
								</el-select>
								<el-input placeholder="请输入详细地址" v-model="baseForm.unitAddress"></el-input>
							</div>
						</el-form-item>
					</div>
					<div class="col-item">
						<el-form-item label="楼宇" prop="building">
							<el-select v-model="baseForm.building" placeholder="请选择" style="width: 100%">
								<el-option v-for="(it, ind) in buildingListDict" :key="ind" :label="it.label"
									:value="it.value"></el-option>
							</el-select>
						</el-form-item>
					</div>
				</div>
				<div class="row-item">
					<div class="col-item">
						<el-form-item label="联系人" prop="linkmanName">
							<el-input v-model="baseForm.linkmanName" placeholder="请输入"></el-input>
						</el-form-item>
					</div>
					<div class="col-item">
						<el-form-item label="联系人电话" prop="linkmanPhone">
							<el-input v-model="baseForm.linkmanPhone" placeholder="请输入"></el-input>
						</el-form-item>
					</div>
				</div>
				<div class="row-item">
					<div class="col-item">
						<el-form-item label="标签" prop="relationLabelCode">
							<div class="flex">
								<el-select v-model="baseForm.relationLabelCode" placeholder="请选择" style="width: 90%" :disabled="enterpriseId && baseForm.relationLabelCode === 'GXBQ006'">
									<el-option v-for="(it, ind) in relationLabelDict" :key="ind" :label="it.label"
										:value="it.value" :disabled="it.value === 'GXBQ006'"></el-option>
								</el-select>
								<el-tooltip placement="right" effect="light">
									<div slot="content">
										如需设定成单标签，请添加成单记录
									</div>
									<svg-icon style="cursor: pointer;" class-name="dangerous-icon" icon-class="dangerous" />
								</el-tooltip>
							</div>
						</el-form-item>
					</div>
					<div class="col-item">
						<el-form-item label="企业类型" prop="companyOrgType">
							<el-select v-model="baseForm.companyOrgType" placeholder="请选择" style="width: 100%">
								<el-option v-for="(it, ind) in companyOrgTypeDict" :key="ind" :label="it.label"
									:value="it.value"></el-option>
							</el-select>
						</el-form-item>
					</div>
				</div>
				<div class="row-item">
					<div class="col-item">
						<el-form-item label="人数" prop="staffNumRange">
							<el-input v-model="baseForm.staffNumRange" placeholder="请输入"></el-input>
						</el-form-item>
					</div>
				</div>
			</div>
		</el-form>
		<el-form ref="dynamicForm" :model="dynamicForm" class="dynamic-form">
			<div class="form-part">
				<div class="title">资产信息</div>
				<!--域名-->
				<div class="list-item" v-for="(item, index) in dynamicForm.domainFormList" :key="index">
					<div class="left-form">
						<div class="form-item">
							<!-- <el-form-item :label="`域名${index + 1}`" :prop="'domainFormList.' + index + '.domainName'"
								:rules="{required: true, message: '请输入域名', trigger: 'blur'}">
								<el-input placeholder="请输入域名" v-model="item.domainName"></el-input>
							</el-form-item> -->
							<el-form-item :label="`域名${index + 1}`" :prop="'domainFormList.' + index + '.domainName'">
								<el-input placeholder="请输入域名" v-model="item.domainName"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="ICP备案号" :prop="'domainFormList.' + index + '.icpRegCode'">
								<el-input placeholder="请输入ICP备案号" v-model="item.icpRegCode"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="公安备案号" :prop="'domainFormList.' + index + '.policeRegCode'">
								<el-input placeholder="请输入公安备案号" v-model="item.policeRegCode"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="网站名称" :prop="'domainFormList.' + index + '.websiteName'">
								<el-input placeholder="请输入网站名称" v-model="item.websiteName"></el-input>
							</el-form-item>
						</div>
					</div>
					<div v-if="roles[0].authority !== 'ROLE_SUPPORT'" class="right-icon">
						<i v-if="index == 0" class="el-icon-circle-plus-outline" @click="add('domainForm')"></i>
						<i v-else class="el-icon-remove-outline" @click="del(index, item, 'domainForm')"></i>
					</div>
				</div>
				<!--已评测系统-->
				<div class="list-item" v-for="(item, index) in dynamicForm.systemFormList" :key="index">
					<div class="left-form">
						<div class="form-item">
							<el-form-item :label="`已评测系统名称${index + 1}`"
								:prop="'systemFormList.' + index + '.systemName'">
								<el-input placeholder="请输入已评测系统名称" v-model="item.systemName"></el-input>
							</el-form-item>
							<!-- <el-form-item :label="`已评测系统名称${index + 1}`"
								:prop="'systemFormList.' + index + '.systemName'"
								:rules="{required: true, message: '请输入已评测系统名称', trigger: 'blur'}">
								<el-input placeholder="请输入已评测系统名称" v-model="item.systemName"></el-input>
							</el-form-item> -->
						</div>
						<div class="form-item">
							<el-form-item label="保护等级" :prop="'systemFormList.' + index + '.systemLevel'">
								<el-select placeholder="请选择保护等级" v-model="item.systemLevel">
									<el-option v-for="(it, ind) in systemLevelDict" :key="ind" :label="it.label"
										:value="it.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="定级方式" :prop="'systemFormList.' + index + '.gradingType'">
								<el-select placeholder="请选择定级方式" v-model="item.gradingType">
									<el-option v-for="(it, ind) in gradingTypeDict" :key="ind" :label="it.label"
										:value="it.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="测评时间" :prop="'systemFormList.' + index + '.testTime'">
								<el-input placeholder="请输入测评时间" v-model="item.testTime"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="测评机构" :prop="'systemFormList.' + index + '.testOrg'">
								<el-input placeholder="请输入测评机构" v-model="item.testOrg"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="复测情况" :prop="'systemFormList.' + index + '.hasRetest'">
								<el-select placeholder="请选择复测情况" v-model="item.hasRetest">
									<el-option v-for="(it, ind) in hasRetestDict" :key="ind" :label="it.label"
										:value="it.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="复测机构" :prop="'systemFormList.' + index + '.retestOrg'">
								<el-input placeholder="请输入复测机构" v-model="item.retestOrg"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="等保编号" :prop="'systemFormList.' + index + '.gradingProtectionNo'">
								<el-input placeholder="请输入等保编号" v-model="item.gradingProtectionNo"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="评估机构" :prop="'unSystemFormList.' + index + '.evalOrg'">
								<el-input placeholder="请输入评估机构" v-model="item.evalOrg"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="安全评分" :prop="'unSystemFormList.' + index + '.securityScore'">
								<el-input placeholder="请输入安全评分" v-model="item.securityScore"></el-input>
							</el-form-item>
						</div>
					</div>
					<div class="right-icon" v-if="roles[0].authority !== 'ROLE_SUPPORT'">
						<i v-if="index == 0" class="el-icon-circle-plus-outline" @click="add('systemForm')"></i>
						<i v-else class="el-icon-remove-outline" @click="del(index, item, 'systemForm')"></i>
					</div>
				</div>
				<!--未评测系统-->
				<div class="list-item" v-for="(item, index) in dynamicForm.unSystemFormList" :key="index">
					<div class="left-form">
						<div class="form-item">
							<el-form-item :label="`未评测系统名称${index + 1}`"
								:prop="'unSystemFormList.' + index + '.systemName'">
								<el-input placeholder="请输入未评测系统名称" v-model="item.systemName"></el-input>
							</el-form-item>
							<!-- <el-form-item :label="`未评测系统名称${index + 1}`"
								:prop="'unSystemFormList.' + index + '.systemName'"
								:rules="{required: true, message: '请输入未评测系统名称', trigger: 'blur'}">
								<el-input placeholder="请输入未评测系统名称" v-model="item.systemName"></el-input>
							</el-form-item> -->
						</div>
						<div class="form-item">
							<el-form-item label="保护等级" :prop="'unSystemFormList.' + index + '.systemLevel'">
								<el-select placeholder="请选择保护等级" v-model="item.systemLevel">
									<el-option v-for="(it, ind) in systemLevelDict" :key="ind" :label="it.label"
										:value="it.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="定级方式" :prop="'unSystemFormList.' + index + '.gradingType'">
								<el-select placeholder="请选择定级方式" v-model="item.gradingType">
									<el-option v-for="(it, ind) in gradingTypeDict" :key="ind" :label="it.label"
										:value="it.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="评估机构" :prop="'unSystemFormList.' + index + '.evalOrg'">
								<el-input placeholder="请输入评估机构" v-model="item.evalOrg"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="安全评分" :prop="'unSystemFormList.' + index + '.securityScore'">
								<el-input placeholder="请输入安全评分" v-model="item.securityScore"></el-input>
							</el-form-item>
						</div>
					</div>
					<div class="right-icon" v-if="roles[0].authority !== 'ROLE_SUPPORT'">
						<i v-if="index == 0" class="el-icon-circle-plus-outline" @click="add('unSystemForm')"></i>
						<i v-else class="el-icon-remove-outline" @click="del(index, item, 'unSystemForm')"></i>
					</div>
				</div>
				<!--APP-->
				<div class="list-item" v-for="(item, index) in dynamicForm.appFormList" :key="index">
					<div class="left-form">
						<div class="form-item">
							<el-form-item :label="`APP名称${index + 1}`" :prop="'appFormList.' + index + '.appName'">
								<el-input placeholder="请输入APP名称" v-model="item.appName"></el-input>
							</el-form-item>
							<!-- <el-form-item :label="`APP名称${index + 1}`" :prop="'appFormList.' + index + '.appName'"
								:rules="{required: true, message: '请输入APP名称', trigger: 'blur'}">
								<el-input placeholder="请输入APP名称" v-model="item.appName"></el-input>
							</el-form-item> -->
						</div>
						<div class="form-item">
							<el-form-item label="运行平台" :prop="'appFormList.' + index + '.platform'">
								<el-input placeholder="请输入运行平台" v-model="item.platform"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="ICP备案号" :prop="'appFormList.' + index + '.icpRegCode'">
								<el-input placeholder="请输入ICP备案号" v-model="item.icpRegCode"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="公安备案号" :prop="'appFormList.' + index + '.policeRegCode'">
								<el-input placeholder="请输入公安备案号" v-model="item.policeRegCode"></el-input>
							</el-form-item>
						</div>
					</div>
					<div class="right-icon" v-if="roles[0].authority !== 'ROLE_SUPPORT'">
						<i v-if="index == 0" class="el-icon-circle-plus-outline" @click="add('appForm')"></i>
						<i v-else class="el-icon-remove-outline" @click="del(index, item, 'appForm')"></i>
					</div>
				</div>
				<!--小程序-->
				<div class="list-item" v-for="(item, index) in dynamicForm.appletFormList" :key="index">
					<div class="left-form">
						<div class="form-item">
							<el-form-item :label="`小程序名称${index + 1}`"
								:prop="'appletFormList.' + index + '.appletName'">
								<el-input placeholder="请输入小程序名称" v-model="item.appletName"></el-input>
							</el-form-item>
							<!-- <el-form-item :label="`小程序名称${index + 1}`" :prop="'appletFormList.' + index + '.appletName'"
								:rules="{required: true, message: '请输入小程序名称', trigger: 'blur'}">
								<el-input placeholder="请输入小程序名称" v-model="item.appletName"></el-input>
							</el-form-item> -->
						</div>
						<div class="form-item">
							<el-form-item label="APPID" :prop="'appletFormList.' + index + '.appletId'">
								<el-input placeholder="请输入APPID" v-model="item.appletId"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="ICP备案号" :prop="'appletFormList.' + index + '.icpRegCode'">
								<el-input placeholder="请输入ICP备案号" v-model="item.icpRegCode"></el-input>
							</el-form-item>
						</div>
						<div class="form-item">
							<el-form-item label="公安备案号" :prop="'appletFormList.' + index + '.policeRegCode'">
								<el-input placeholder="请输入公安备案号" v-model="item.policeRegCode"></el-input>
							</el-form-item>
						</div>
					</div>
					<div class="right-icon" v-if="roles[0].authority !== 'ROLE_SUPPORT'">
						<i v-if="index == 0" class="el-icon-circle-plus-outline" @click="add('appletForm')"></i>
						<i v-else class="el-icon-remove-outline" @click="del(index, item, 'appletForm')"></i>
					</div>
				</div>
			</div>
		</el-form>
		<div class="btn-group">
			<el-button class="btn pass" @click="submit">
				确认修改
				<i class="el-icon-arrow-right"></i>
			</el-button>
		</div>
    <orderFormDialog v-model="orderFormDialogVisible" :unitOrgCode="unitOrgCode" />
	</div>
</template>

<script>
	import {
		getEditEnterpriseInfo,
		listEditDomainInfo,
		listEditSystemInfo,
		listEditAppInfo,
		listEditAppletInfo,
		commitEnterpriseUpdate
	} from "@/api/enterprise";
	import orderFormDialog from './component/orderFormDialog.vue';
	export default {
		components: {
			orderFormDialog
		},
		data() {
			const validateUnitStreet = (rule, value, callback) => {
				if (!value) {
					callback(new Error("请输入所属街道"));
				} else if (!this.baseForm.unitAddress) {
					callback(new Error("请输入详细地址"));
				} else {
					callback();
				}
			};
			return {
				baseForm: {
					unitName: "",
					unitOrgCode: "",
					supportUnitCode: "",
					industryLabelCode: "",
					unitStreet: "",
					unitAddress: "",
					building: "",
					hasLinkman: "",
					relationLabelCode: "",
					linkmanName: "",
					linkmanPhone: "",
					companyOrgType: "",
					staffNumRange: "",
				},
				baseRules: {
					unitName: [{
						required: true,
						message: "请输入单位名称",
						trigger: "blur"
					}],
					unitOrgCode: [{
						required: true,
						message: "请输入统一信用代码",
						trigger: "blur"
					}],
					supportUnitCode: [{
						required: true,
						message: "请输入销售员",
						trigger: "blur"
					}],
					unitStreet: [{
						required: true,
						trigger: "blur",
						validator: validateUnitStreet
					}],
					linkmanName: [{
						required: true,
						message: "请输入联系人",
						trigger: "blur"
					}],
					linkmanPhone: [
						{
							required: true,
							message: "请输入联系电话",
							trigger: "blur"
						},
						{
							pattern: /^1[3456789]\d{9}$/,
							message: "手机号输入错误"
						}
					],
					// companyOrgType: [
					// 	{
					// 		required: true,
					// 		message: "请选择企业类型",
					// 		trigger: "change"
					// 	},
					// ],
					staffNumRange: [
						// {
						// 	required: true,
						// 	message: "请输入人数",
						// 	trigger: "blur"
						// },
						{
							pattern: /^([1-9]\d*)$/,
							message: "人数输入错误"
						}
					],
				},
				dynamicForm: {
					domainFormList: [],
					systemFormList: [],
					unSystemFormList: [],
					appFormList: [],
					appletFormList: []
				},
				delDomainFormList: [],
				domainForm: {
					domainName: "",
					icpRegCode: "",
					policeRegCode: "",
					websiteName: ""
				},
				delSystemFormList: [],
				systemForm: {
					systemName: "",
					systemLevel: "",
					gradingType: "",
					testTime: "",
					testOrg: "",
					hasRetest: "",
					retestOrg: "",
					gradingProtectionNo: ""
				},
				delUnSystemFormList: [],
				unSystemForm: {
					systemName: "",
					systemLevel: "",
					gradingType: "",
					evalOrg: ""
				},
				delAppFormList: [],
				appForm: {
					appName: "",
					platform: "",
					icpRegCode: "",
					policeRegCode: ""
				},
				delAppletFormList: [],
				appletForm: {
					appletName: "",
					appletId: "",
					icpRegCode: "",
					policeRegCode: ""
				},
      	orderFormDialogVisible: false,
			};
		},
		computed: {
			roles() {
				return this.$store.getters.roles;
			},
			enterpriseId() {
				return this.$route.query.enterpriseId;
			},
			unitOrgCode() {
				return this.$route.query.unitOrgCode;
			},
			supportUnitDict() {
				const dict = this.$store.getters.dict;
				const list = [];
				for (let value in dict.supportUnit) {
					list.push({
						label: dict.supportUnit[value],
						value
					});
				}
				return list;
			},
			unitStreetDict() {
				const dict = this.$store.getters.dict;
				const list = [];
				for (let value in dict.unitStreet) {
					list.push({
						label: dict.unitStreet[value],
						value
					});
				}
				return list;
			},
			systemLevelDict() {
				const dict = this.$store.getters.dict;
				const list = [];
				for (let value in dict.systemLevel) {
					list.push({
						label: dict.systemLevel[value],
						value
					});
				}
				return list;
			},
			gradingTypeDict() {
				const dict = this.$store.getters.dict;
				const list = [];
				for (let value in dict.gradingType) {
					list.push({
						label: dict.gradingType[value],
						value
					});
				}
				return list;
			},
			hasRetestDict() {
				const list = [{
						label: "是",
						value: 1
					},
					{
						label: "否",
						value: 0
					}
				];
				return list;
			},
			labelHybqDict() {
				const dict = this.$store.getters.dict;
				const list = [];
				for (let value in dict.labelHybq) {
					list.push({
						label: dict.labelHybq[value],
						value
					});
				}
				return list;
			},
			buildingListDict() {
				const dict = this.$store.getters.dict;
				const list = [];
				for (let value in dict.buildingList) {
					list.push({
						label: dict.buildingList[value],
						value
					});
				}
				return list;
			},
			hasLinkmanDict() {
				const list = [{
						label: "有",
						value: 1
					},
					{
						label: "无",
						value: 0
					}
				];
				return list;
			},
			relationLabelDict() {
				const dict = this.$store.getters.dict;
				const list = [];
				for (let value in dict.relationLabel) {
					list.push({
						label: dict.relationLabel[value],
						value
					})
				}
				return list;
			},
			companyOrgTypeDict() {
				const dict = this.$store.getters.dict
				const list = []
				for (let value in dict.companyOrgType) {
					list.push({
						label: dict.companyOrgType[value],
						value
					})
				}
				return list
			}
		},
		mounted() {
			if (this.enterpriseId) {
				this.initDetail();
			} else {
				this.dynamicForm.domainFormList = [this.domainForm];
				this.dynamicForm.systemFormList = [this.systemForm];
				this.dynamicForm.unSystemFormList = [this.unSystemForm];
				this.dynamicForm.appFormList = [this.appForm];
				this.dynamicForm.appletFormList = [this.appletForm];
			}
		},
		methods: {
			initDetail() {
				this.getEditEnterpriseInfo();
				this.listEditDomainInfo();
				this.listEditUnSystemInfo();
				this.listEditSystemInfo();
				this.listEditAppInfo();
				this.listEditAppletInfo();
			},
			// 获取企业基本信息
			getEditEnterpriseInfo() {
				getEditEnterpriseInfo({
					enterpriseId: this.enterpriseId
				}).then(res => {
					console.log(res);
					this.baseForm = res.data;
				});
			},
			// 获取域名资产数据
			listEditDomainInfo() {
				listEditDomainInfo({
					unitOrgCode: this.unitOrgCode
				}).then(res => {
					console.log(res);
					const list = res.data.filter(it => it.operateType !== 3),
						delList = res.data.filter(it => it.operateType === 3);
					this.delDomainFormList = delList;
					if (list.length === 0) {
						this.dynamicForm.domainFormList = [this.domainForm];
					} else {
						this.dynamicForm.domainFormList = res.data;
					}
				});
			},
			// 获取系统资产数据（未测评）
			listEditUnSystemInfo() {
				listEditSystemInfo({
					unitOrgCode: this.unitOrgCode,
					hasTest: 0
				}).then(res => {
					console.log(res);
					const list = res.data.filter(it => it.operateType !== 3),
						delList = res.data.filter(it => it.operateType === 3);
					this.delUnSystemFormList = delList;
					if (list.length === 0) {
						this.dynamicForm.unSystemFormList = [this.unSystemForm];
					} else {
						this.dynamicForm.unSystemFormList = res.data;
					}
				});
			},

			// 获取系统资产数据（已测评）
			listEditSystemInfo() {
				listEditSystemInfo({
					unitOrgCode: this.unitOrgCode,
					hasTest: 1
				}).then(res => {
					console.log(res);
					const list = res.data.filter(it => it.operateType !== 3),
						delList = res.data.filter(it => it.operateType === 3);
					this.delSystemFormList = delList;
					if (list.length === 0) {
						this.dynamicForm.systemFormList = [this.systemForm];
					} else {
						this.dynamicForm.systemFormList = res.data;
					}
				});
			},
			// 获取APP资产数据
			listEditAppInfo() {
				listEditAppInfo({
					unitOrgCode: this.unitOrgCode
				}).then(res => {
					console.log(res);
					const list = res.data.filter(it => it.operateType !== 3),
						delList = res.data.filter(it => it.operateType === 3);
					this.delAppFormList = delList;
					if (list.length === 0) {
						this.dynamicForm.appFormList = [this.appForm];
					} else {
						this.dynamicForm.appFormList = res.data;
					}
				});
			},
			// 获取小程序资产数据
			listEditAppletInfo() {
				listEditAppletInfo({
					unitOrgCode: this.unitOrgCode
				}).then(res => {
					console.log(res);
					const list = res.data.filter(it => it.operateType !== 3),
						delList = res.data.filter(it => it.operateType === 3);
					this.delAppletFormList = delList;
					if (list.length === 0) {
						this.dynamicForm.appletFormList = [this.appletForm];
					} else {
						this.dynamicForm.appletFormList = res.data;
					}
				});
			},
			add(name) {
				this.dynamicForm[name + "List"].splice(1, 0, {
					...this[name]
				});
				
			},
			del(index, item, name) {
				if (item.id) {
					const it = {
						...item,
						operateType: 3
					};
					this["del" + name + "List"].push(it);
				}
				this.dynamicForm[name + "List"].splice(index, 1);
			},
			isEmpty(obj) {
				for (let key in obj) {
					if (obj.hasOwnProperty(key)) {
						if (obj[key] !== null && obj[key] !== undefined && obj[key] !== '') {
							return false;
						}
					}
				}
				return true;
			},
			submit() {
				this.$refs["baseForm"].validate(valid => {
					if (valid) {
						this.$refs["dynamicForm"].validate(dynamicValid => {
							console.log(dynamicValid, 'dynamicValid');
							
							if (dynamicValid) {
								let domainFormList = [], systemFormList = [], unSystemFormList = [], appFormList = [], appletFormList = [];
								this.dynamicForm.domainFormList.forEach(it => {
								  if (!this.isEmpty(it)) {
										domainFormList.push(it)
									}
								})
								this.dynamicForm.systemFormList.forEach(it => {
									if (!this.isEmpty(it)) {
										systemFormList.push(it)
									}
								})
								this.dynamicForm.unSystemFormList.forEach(it => {
									if (!this.isEmpty(it)) {
										unSystemFormList.push(it)
									}
								})
								this.dynamicForm.appFormList.forEach(it => {
									if (!this.isEmpty(it)) {
										appFormList.push(it)
									}
								})
								this.dynamicForm.appletFormList.forEach(it => {
									if (!this.isEmpty(it)) {
										appletFormList.push(it)
									}
								})
								commitEnterpriseUpdate({
									enterpriseId: this.enterpriseId,
									enterprise: {
										...this.baseForm,
										operateType: this.enterpriseId ? 2 : 1
									},
									domain: [
										...domainFormList.map(it => {
											return {
												...it,
												unitOrgCode: it.unitOrgCode ?
													it.unitOrgCode : this.baseForm
													.unitOrgCode,
												operateType: it.id ? 2 : 1
											};
										}),
										...this.delDomainFormList
									],
									system: [
										...systemFormList.map(it => {
											return {
												...it,
												unitOrgCode: it.unitOrgCode ?
													it.unitOrgCode : this.baseForm
													.unitOrgCode,
												operateType: it.id ? 2 : 1
											};
										}),
										...this.delSystemFormList,
										...unSystemFormList.map(it => {
											return {
												...it,
												unitOrgCode: it.unitOrgCode ?
													it.unitOrgCode : this.baseForm
													.unitOrgCode,
												operateType: it.id ? 2 : 1
											};
										}),
										...this.delUnSystemFormList
									],
									app: [
										...appFormList.map(it => {
											return {
												...it,
												unitOrgCode: it.unitOrgCode ?
													it.unitOrgCode : this.baseForm
													.unitOrgCode,
												operateType: it.id ? 2 : 1
											};
										}),
										...this.delAppFormList
									],
									applet: [
										...appletFormList.map(it => {
											return {
												...it,
												unitOrgCode: it.unitOrgCode ?
													it.unitOrgCode : this.baseForm
													.unitOrgCode,
												operateType: it.id ? 2 : 1
											};
										}),
										...this.delAppletFormList
									]
								}).then(res => {
									this.$message.success("操作成功");
									this.$store.dispatch('app/setReLoad', true);
									setTimeout(() => {
										this.goBack();
									}, 1000);
								});
							}
						});
					}
				});
			},
			showDialog(name) {
				this[name] = true;
			},
			goBack() {
				// this.$router.go(-1);
				window.close();
			}
		}
	};
</script>

<style lang="scss" scoped>
	.detail-container {
		padding: 0.25rem;

		.name {
			font-size: 0.33rem;
			margin: 0.13rem 0 0.25rem;
		}

		.base-form {
			margin-bottom: 0.35rem;
		}

		.form-part {
			background: rgba(255, 255, 255, 0.6);
			box-shadow: 0rem 0.05rem 0.8rem 0.4rem rgba(0, 0, 0, 0.05);
			border-radius: 0.05rem 0.05rem 0.05rem 0.05rem;
			border: 0.01rem solid #ffffff;
			padding: 0.19rem;

			.title {
				font-size: 0.2rem;
				color: #000822;
				margin-bottom: 0.38rem;
				display: flex;
				align-items: center;

				&::before {
					content: "";
					display: block;
					width: 0.03rem;
					height: 0.2rem;
					background: #000822;
					margin-right: 0.1rem;
				}
				.mr {
					margin-right: 20px;
				}
			}

			.row-item {
				padding-left: 0.1rem;
				display: flex;
				justify-content: space-between;

				.col-item {
					width: 45%;
					.flex {
						display: flex;
						justify-content: space-between;
						align-items: center;
					}
				}
			}

			.list-item {
				height: 1.23rem;
				padding: 0 0.45rem 0 0.3rem;
				background: rgba(0, 8, 34, 0.05);
				border-radius: 0.05rem 0.05rem 0.05rem 0.05rem;
				margin-bottom: 0.2rem;
				display: flex;
				justify-content: space-between;
				align-items: center;

				.left-form {
					display: flex;

					.form-item {
						::v-deep {
							.el-form-item {
								margin-bottom: 0;
							}

							.el-input__inner {
								background-color: transparent;
								border: none;
								padding-left: 0;
							}
						}
					}
				}
			}
		}

		.btn-group {
			margin-top: 0.38rem;
			text-align: center;

			.btn {
				width: 1.85rem;
				height: 0.5rem;
				color: #ffffff;
				border: none;

				&.pass {
					background: #1c4088;
				}
			}
		}
	}
</style>